

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>agpy.cutout &mdash; agpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="../../_static/extra.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="agpy 0.1.2 documentation" href="../../index.html" />
    <link rel="up" title="agpy" href="../agpy.html" />
     
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setDomainName', 'pyspeckit.bitbucket.org']);
      _gaq.push(['_setAllowHash', false]);
      _gaq.push(['_trackPageview']);


    </script>
    <link rel="stylesheet" type="text/css" href="../../_static/extra.css" />
  </head>
  <body>
    <div class="header-wrapper">
      <div class="header">
        <h1><a href="../../index.html">agpy 0.1.2 documentation</a></h1>
        <div class="rel">
          <a href="http://agpy.googlecode.com">agpy Home </a>  |
          <a href=../../index.html>Docs Home </a>  |
          <a href="http://code.google.com/p/agpy/w/list">Wiki</a>  |
          <a href=../../search.html>Search </a>
        </div>
       </div>
    </div>

    <div class="content-wrapper">
      <div class="content">
        <div class="document">
            
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for agpy.cutout</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">======</span>
<span class="sd">Cutout</span>
<span class="sd">======</span>

<span class="sd">Generate a cutout image from a .fits file</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">pyfits</span>
<span class="kn">import</span> <span class="nn">numpy</span>
<span class="kn">import</span> <span class="nn">pywcs</span>
<span class="kn">import</span> <span class="nn">coords</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">montage</span>
    <span class="kn">import</span> <span class="nn">os</span>
    <span class="n">CanUseMontage</span><span class="o">=</span><span class="bp">True</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="n">CanUseMontage</span><span class="o">=</span><span class="bp">False</span>

<div class="viewcode-block" id="DimensionError"><a class="viewcode-back" href="../../agpy.html#agpy.cutout.DimensionError">[docs]</a><span class="k">class</span> <span class="nc">DimensionError</span><span class="p">(</span><span class="ne">ValueError</span><span class="p">):</span>
    <span class="k">pass</span>
</div>
<div class="viewcode-block" id="cutout"><a class="viewcode-back" href="../../agpy.html#agpy.cutout.cutout">[docs]</a><span class="k">def</span> <span class="nf">cutout</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">xc</span><span class="p">,</span> <span class="n">yc</span><span class="p">,</span> <span class="n">xw</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span> <span class="n">yw</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span> <span class="n">units</span><span class="o">=</span><span class="s">&#39;pixels&#39;</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
        <span class="n">clobber</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">useMontage</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">coordsys</span><span class="o">=</span><span class="s">&#39;celestial&#39;</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Inputs:</span>
<span class="sd">        file  - .fits filename or pyfits HDUList (must be 2D)</span>
<span class="sd">        xc,yc - x and y coordinates in the fits files&#39; coordinate system (CTYPE)</span>
<span class="sd">        xw,yw - x and y width (pixels or wcs)</span>
<span class="sd">        units - specify units to use: either pixels or wcs</span>
<span class="sd">        outfile - optional output file</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="nb">str</span><span class="p">):</span>
        <span class="nb">file</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="n">opened</span><span class="o">=</span><span class="bp">True</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="n">pyfits</span><span class="o">.</span><span class="n">HDUList</span><span class="p">):</span>
        <span class="nb">file</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="n">opened</span><span class="o">=</span><span class="bp">False</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;cutout: Input file is wrong type (string or HDUList are acceptable).&quot;</span><span class="p">)</span>

    <span class="n">head</span> <span class="o">=</span> <span class="nb">file</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">header</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">DimensionError</span><span class="p">(</span><span class="s">&quot;Too many (</span><span class="si">%i</span><span class="s">) dimensions!&quot;</span> <span class="o">%</span> <span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS&#39;</span><span class="p">])</span>
    <span class="n">cd1</span> <span class="o">=</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;CDELT1&#39;</span><span class="p">)</span> <span class="k">if</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;CDELT1&#39;</span><span class="p">)</span> <span class="k">else</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;CD1_1&#39;</span><span class="p">)</span>
    <span class="n">cd2</span> <span class="o">=</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;CDELT2&#39;</span><span class="p">)</span> <span class="k">if</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;CDELT2&#39;</span><span class="p">)</span> <span class="k">else</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;CD2_2&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">cd1</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">cd2</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;Missing CD or CDELT keywords in header&quot;</span><span class="p">)</span>
    <span class="n">wcs</span> <span class="o">=</span> <span class="n">pywcs</span><span class="o">.</span><span class="n">WCS</span><span class="p">(</span><span class="n">head</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">units</span> <span class="o">==</span> <span class="s">&#39;wcs&#39;</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">coordsys</span><span class="o">==</span><span class="s">&#39;celestial&#39;</span> <span class="ow">and</span> <span class="n">wcs</span><span class="o">.</span><span class="n">wcs</span><span class="o">.</span><span class="n">lngtyp</span><span class="o">==</span><span class="s">&#39;GLON&#39;</span><span class="p">:</span>
            <span class="n">xc</span><span class="p">,</span><span class="n">yc</span> <span class="o">=</span> <span class="n">coords</span><span class="o">.</span><span class="n">Position</span><span class="p">((</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">),</span><span class="n">system</span><span class="o">=</span><span class="n">coordsys</span><span class="p">)</span><span class="o">.</span><span class="n">galactic</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">coordsys</span><span class="o">==</span><span class="s">&#39;galactic&#39;</span> <span class="ow">and</span> <span class="n">wcs</span><span class="o">.</span><span class="n">wcs</span><span class="o">.</span><span class="n">lngtyp</span><span class="o">==</span><span class="s">&#39;RA&#39;</span><span class="p">:</span>
            <span class="n">xc</span><span class="p">,</span><span class="n">yc</span> <span class="o">=</span> <span class="n">coords</span><span class="o">.</span><span class="n">Position</span><span class="p">((</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">),</span><span class="n">system</span><span class="o">=</span><span class="n">coordsys</span><span class="p">)</span><span class="o">.</span><span class="n">j2000</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">useMontage</span> <span class="ow">and</span> <span class="n">CanUseMontage</span><span class="p">:</span>
        <span class="n">head</span><span class="p">[</span><span class="s">&#39;CRVAL1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xc</span>
        <span class="n">head</span><span class="p">[</span><span class="s">&#39;CRVAL2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">yc</span>
        <span class="k">if</span> <span class="n">units</span> <span class="o">==</span> <span class="s">&#39;pixels&#39;</span><span class="p">:</span>
            <span class="n">head</span><span class="p">[</span><span class="s">&#39;CRPIX1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xw</span>
            <span class="n">head</span><span class="p">[</span><span class="s">&#39;CRPIX2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">yw</span>
            <span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">xw</span><span class="o">*</span><span class="mi">2</span><span class="p">)</span>
            <span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">yw</span><span class="o">*</span><span class="mi">2</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">units</span> <span class="o">==</span> <span class="s">&#39;wcs&#39;</span><span class="p">:</span>
            
            <span class="n">cdelt</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">cd1</span><span class="o">**</span><span class="mi">2</span><span class="o">+</span><span class="n">cd2</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
            <span class="n">head</span><span class="p">[</span><span class="s">&#39;CRPIX1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">xw</span>   <span class="o">/</span> <span class="n">cdelt</span>
            <span class="n">head</span><span class="p">[</span><span class="s">&#39;CRPIX2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">yw</span>   <span class="o">/</span> <span class="n">cdelt</span>
            <span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">xw</span><span class="o">*</span><span class="mi">2</span> <span class="o">/</span> <span class="n">cdelt</span><span class="p">)</span>
            <span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">yw</span><span class="o">*</span><span class="mi">2</span> <span class="o">/</span> <span class="n">cdelt</span><span class="p">)</span>

        <span class="n">head</span><span class="o">.</span><span class="n">toTxtFile</span><span class="p">(</span><span class="s">&#39;temp_montage.hdr&#39;</span><span class="p">,</span><span class="n">clobber</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="n">newfile</span> <span class="o">=</span> <span class="n">montage</span><span class="o">.</span><span class="n">wrappers</span><span class="o">.</span><span class="n">reproject_hdu</span><span class="p">(</span><span class="nb">file</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">header</span><span class="o">=</span><span class="s">&#39;temp_montage.hdr&#39;</span><span class="p">,</span><span class="n">exact_size</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;temp_montage.hdr&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>

        <span class="n">xx</span><span class="p">,</span><span class="n">yy</span> <span class="o">=</span> <span class="n">wcs</span><span class="o">.</span><span class="n">wcs_sky2pix</span><span class="p">(</span><span class="n">xc</span><span class="p">,</span><span class="n">yc</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">units</span><span class="o">==</span><span class="s">&#39;pixels&#39;</span><span class="p">:</span>
            <span class="n">xmin</span><span class="p">,</span><span class="n">xmax</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="n">xx</span><span class="o">-</span><span class="n">xw</span><span class="p">]),</span><span class="n">numpy</span><span class="o">.</span><span class="n">min</span><span class="p">([</span><span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">],</span><span class="n">xx</span><span class="o">+</span><span class="n">xw</span><span class="p">])</span>
            <span class="n">ymin</span><span class="p">,</span><span class="n">ymax</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="n">yy</span><span class="o">-</span><span class="n">yw</span><span class="p">]),</span><span class="n">numpy</span><span class="o">.</span><span class="n">min</span><span class="p">([</span><span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">],</span><span class="n">yy</span><span class="o">+</span><span class="n">yw</span><span class="p">])</span>
        <span class="k">elif</span> <span class="n">units</span><span class="o">==</span><span class="s">&#39;wcs&#39;</span><span class="p">:</span>
            <span class="n">xmin</span><span class="p">,</span><span class="n">xmax</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="n">xx</span><span class="o">-</span><span class="n">xw</span><span class="o">/</span><span class="n">numpy</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">cd1</span><span class="p">)]),</span><span class="n">numpy</span><span class="o">.</span><span class="n">min</span><span class="p">([</span><span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">],</span><span class="n">xx</span><span class="o">+</span><span class="n">xw</span><span class="o">/</span><span class="n">numpy</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">cd1</span><span class="p">)])</span>
            <span class="n">ymin</span><span class="p">,</span><span class="n">ymax</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="n">yy</span><span class="o">-</span><span class="n">yw</span><span class="o">/</span><span class="n">numpy</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">cd2</span><span class="p">)]),</span><span class="n">numpy</span><span class="o">.</span><span class="n">min</span><span class="p">([</span><span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">],</span><span class="n">yy</span><span class="o">+</span><span class="n">yw</span><span class="o">/</span><span class="n">numpy</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">cd2</span><span class="p">)])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;Can&#39;t use units </span><span class="si">%s</span><span class="s">.&quot;</span> <span class="o">%</span> <span class="n">units</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">xmax</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">ymax</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;Max Coordinate is outside of map: </span><span class="si">%f</span><span class="s">,</span><span class="si">%f</span><span class="s">.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">xmax</span><span class="p">,</span><span class="n">ymax</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">ymin</span> <span class="o">&gt;=</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">xmin</span> <span class="o">&gt;=</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;Min Coordinate is outside of map: </span><span class="si">%f</span><span class="s">,</span><span class="si">%f</span><span class="s">.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">xmin</span><span class="p">,</span><span class="n">ymin</span><span class="p">))</span>

        <span class="n">head</span><span class="p">[</span><span class="s">&#39;CRPIX1&#39;</span><span class="p">]</span><span class="o">-=</span><span class="n">xmin</span>
        <span class="n">head</span><span class="p">[</span><span class="s">&#39;CRPIX2&#39;</span><span class="p">]</span><span class="o">-=</span><span class="n">ymin</span>
        <span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">]</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">xmax</span><span class="o">-</span><span class="n">xmin</span><span class="p">)</span>
        <span class="n">head</span><span class="p">[</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">]</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">ymax</span><span class="o">-</span><span class="n">ymin</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&quot;Map has a 0 dimension: </span><span class="si">%i</span><span class="s">,</span><span class="si">%i</span><span class="s">.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;NAXIS1&#39;</span><span class="p">),</span><span class="n">head</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;NAXIS2&#39;</span><span class="p">)))</span>

        <span class="n">img</span> <span class="o">=</span> <span class="nb">file</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">ymin</span><span class="p">:</span><span class="n">ymax</span><span class="p">,</span><span class="n">xmin</span><span class="p">:</span><span class="n">xmax</span><span class="p">]</span>
        <span class="n">newfile</span> <span class="o">=</span> <span class="n">pyfits</span><span class="o">.</span><span class="n">PrimaryHDU</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">img</span><span class="p">,</span><span class="n">header</span><span class="o">=</span><span class="n">head</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span> <span class="k">print</span> <span class="s">&quot;Cut image </span><span class="si">%s</span><span class="s"> with dims </span><span class="si">%s</span><span class="s"> to </span><span class="si">%s</span><span class="s">.  xrange: </span><span class="si">%f</span><span class="s">:</span><span class="si">%f</span><span class="s">, yrange: </span><span class="si">%f</span><span class="s">:</span><span class="si">%f</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="nb">file</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span><span class="n">img</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span><span class="n">xmin</span><span class="p">,</span><span class="n">xmax</span><span class="p">,</span><span class="n">ymin</span><span class="p">,</span><span class="n">ymax</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span><span class="nb">str</span><span class="p">):</span>
        <span class="n">newfile</span><span class="o">.</span><span class="n">writeto</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span><span class="n">clobber</span><span class="o">=</span><span class="n">clobber</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">opened</span><span class="p">:</span>
        <span class="nb">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">newfile</span></div>
</pre></div>

          </div>
        </div>
      </div>
        </div>
        <div class="sidebar">
          <h3>Table Of Contents</h3>
          <ul>
<li class="toctree-l1"><a class="reference internal" href="../../agpy.html">Adam Ginsburg&#8217;s Python Code (agpy)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../image_tools.html">Image Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fft_tools.html">AG_fft_tools Package</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../plfit.html">plfit Package</a></li>
</ul>

          <h3 style="margin-top: 1.5em;">Search</h3>
          <form class="search" action="../../search.html" method="get">
            <input type="text" name="q" />
            <input type="submit" value="Go" />
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>
          <p class="searchtip" style="font-size: 90%">
            Enter search terms or a module, class or function name.
          </p>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

    <div class="footer">
      &copy; Copyright 2011, Adam Ginsburg.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2pre.
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-6253248-2']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
        
    </div>
  </body>
</html>